?><?

function send_mail_to($from,$addrs,$subject,$backcall="build_mail"){
  global $form_as_result;$form_as_result=true;    
  $subject  ="=?Windows-1251?B?".base64_encode($subject)."?=";
  if(is_a($from,"cls_user_item")){
  	$headers  = "From: ".$from->as_email()."\n";
  }else{
  	$headers  = "From: $from\n";
  }
  $headers .= "MIME-Version: 1.0\n";
  $headers .= "Content-Type: text/html;charset= windows-1251\n";    
  $headers .= "X-Mailer: GrapeCMS\n";
  if(!is_array($backcall)){
	  $message=$this->getMethodOutput($backcall);
	}else{
	  $obj=$backcall[0];
	  $method=$backcall[1];
	  $message=$obj->getMethodOutput($method);
  }
  $count=0;
  if(is_array($addrs)){
    $addr_list="";
    $chunk=count($addrs)<100?0:20;
    foreach($addrs as $addr){
      $addr=trim($addr);
      if($addr!=""){
        $addr_list.=($addr_list!=""?",":"").$addr;
        if($count>=$chunk){
          if($chunk!=0){
            $sheaders=$headers."BCC: $addr_list\n";
            mail($from, $subject, $message, $sheaders);$addr_list="";
          }else{
            mail($addr, $subject, $message, $headers);
          }
          $count=0;
        }
        $count++;
      }
    }      
    if($chunk!=0&&$count!=0){
      $sheaders=$headers."BCC: $addr_list\n";
      mail($from, $subject, $message, $sheaders);
      $addr_list="";
    }      
  }else{
    mail($addrs, $subject, $message, $headers);
  }    
}

function hide_mail($mail){
  $mail=explode("@",$mail);
  $out="";
  $out.="<script type=\"text/javascript\">";
  $out.="var string1 = \"".$mail[0]."\";";
  $out.="var string2 = \"@\";";
  $out.="var string3 = \"".$mail[1]."\";";
  $out.="var string4 = string1 + string2 + string3;";
  $out.="document.write(\"<a class='mail' href=\" + \"mail\" + \"to:\" + string1 + string2 + string3 + \"><span>\" + string4 + \"</span></a>\");";
  $out.="</script>";
  return $out;
}
function draw_mail($mail){
  $mail=explode("@",$mail);
	?>
	<script type='text/javascript'>
	var string1 = '<?=$mail[0]?>';
	var string2 = '@';
	var string3 = '<?=$mail[1]?>';
	var string4 = string1 + string2 + string3;
	document.write("<a class='mail'  href=" + "mail" + "to:" + string1 + string2 + string3 + ">" + string4 + "</a>");
  </script><?
}